package com.melody.android.ui.activity

import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import com.melody.android.MainActivity
import com.melody.android.MelodyApplication
import com.melody.android.R
import com.melody.android.logic.util.getLoginState

@SuppressLint("CustomSplashScreen")
class AnimatedSplashActivity : BaseActivity() {

    private val splashDelay: Long = 2500

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_animated_splash)

        // 延迟跳转
        Handler(Looper.getMainLooper()).postDelayed({
            if (isLoggedIn()) {
                startActivity(Intent(this@AnimatedSplashActivity, MainActivity::class.java))
            } else {
                startActivity(Intent(this@AnimatedSplashActivity, LoginActivity::class.java))
            }

            finish()
        }, splashDelay)
    }

    /**
     * 判断是否处于登录状态
     */
    private fun isLoggedIn(): Boolean {
        return getLoginState(MelodyApplication.context)
    }

}